package fm.last.api
{
    import fm.last.BaseTC;
    

    public class ArtistAPITest extends BaseTC
    {
        public function ArtistAPITest()
        {
            super();   
            addTest("testAddTags");
            addTest("testGetEvents");
            addTest("testGetImages");
            addTest("testGetInfo");
            addTest("testGetShouts");
            addTest("testGetSimilar");
            addTest("testGetTags");
            addTest("testGetTopAlbums");
            addTest("testGetTopFans");
            addTest("testGetTopTags");
            addTest("testGetTopTracks");
            addTest("testRemoveTag");
            addTest("testSearch");
            
            // XXX: open it when you want to test
            // addTest("testShare"); 
            // addTest("testShout");         
        }
     
        public function testAddTags():void
        {             
            var getThenRemoveTag:Function = function(xml:XML):void {
                
                var f:Function = expectedPattern("/lfm/tags",/atest[12]/);
                f(xml);
                
                f = expectedPattern("/lfm/tags",/atest3/);
                try {
                    f(xml);    
                    fail("undesired tag exists!");
                } catch (e:Error) {}
                
                lfm_service.artist.removeTag(okNoContent, unexpectedError, "Björk", "atest1");
                lfm_service.artist.removeTag(okNoContent, unexpectedError, "Björk", "atest2");
                
            };
            
            var addThenGetTag:Function = function(xml:XML):void {
                var f:Function = okNoContent;
                f(xml);
                
                lfm_service.artist.getTags(getThenRemoveTag, unexpectedError, "Björk");                
            };  
            
            lfm_service.artist.addTags(addThenGetTag, unexpectedError, "Björk", "atest1,atest2");
                     
        }
        
        public function testGetEvents():void
        {      
            lfm_service.artist.getEvents(expectedPattern("/lfm",/<events/), unexpectedError, "Cher");
        }
        
        public function testGetImages():void
        {            
            
            lfm_service.artist.getImages(expectedPattern("/lfm",/<images/), unexpectedError, "cher");
        }      
        
        public function testGetInfo():void
        {
            lfm_service.artist.getInfo(expectedPattern("/lfm/artist/name",/Cher/), unexpectedError, "Cher");
            lfm_service.artist.getInfo(expectedPattern("/lfm/artist/name",/Cher/), unexpectedError, null, "bfcc6d75-a6a5-4bc6-8282-47aec8531818");
            
            // artist has higher priority than mbid                       
            lfm_service.artist.getInfo(expectedPattern("/lfm/artist/name",/Suede/), unexpectedError, "Suede", "bfcc6d75-a6a5-4bc6-8282-47aec8531818");                        
        }
        
        public function testGetShouts():void
        {            
            lfm_service.artist.getShouts(expectedPattern("/lfm/shouts/shout"), unexpectedError, "cher");
        }
        
        
        public function testGetSimilar():void
        {      
            lfm_service.artist.getSimilar(expectedPattern("/lfm/similarartists"), unexpectedError, "Björk");     
            lfm_service.artist.getSimilar(unexpectedComplete, expectedError, "I_Bet_No_Such_Artist");                
        }   
        
        /** @see testAddTags() */
        public function testGetTags():void
        {     
        }
        
        public function testGetTopAlbums():void
        {            
            lfm_service.artist.getTopAlbums(expectedPattern("/lfm/topalbums"), unexpectedComplete, "Björk");
        }
        
        public function testGetTopFans():void
        {   
            lfm_service.artist.getTopFans(expectedPattern("/lfm/topfans/user"), unexpectedComplete, "Björk");         
        }
        
        public function testGetTopTags():void
        {            
            lfm_service.artist.getTopTags(expectedPattern("/lfm/toptags/tag"), unexpectedComplete, "Björk");
        }
        
        public function testGetTopTracks():void
        {            
            lfm_service.artist.getTopTracks(expectedPattern("/lfm/toptracks/track"), unexpectedComplete, "Björk");
        }
        
        /** @see testAddTags() */
        public function testRemoveTag():void
        {                
            lfm_service.artist.removeTag(unexpectedComplete, expectedError, "Björk", "atest3");
        }
        
        public function testSearch():void
        {      
            lfm_service.artist.search(
                expectedPattern("/lfm/results/artistmatches/artist/name",/Björk/), 
                unexpectedError, 
                "Björk");       
        }
        public function testShare():void
        {            
            lfm_service.artist.share(okNoContent, unexpectedError, "Suede", "vixplore", "testing share");
        }
        
        public function testShout():void
        {            
            lfm_service.artist.shout(okNoContent, unexpectedError, "Björk", "Nr. 1");
        }    
    }
}